package com.base.commons.tools.vo;

import com.alibaba.fastjson.JSONObject;
import com.base.commons.tools.utils.StringUtils;
import lombok.Data;

import java.io.Serializable;

@Data
public class JobParamVO implements Serializable {

    private Integer maxRetries = 3; //重试次数

    private Integer beforeMinutes = 1; //加载N分钟之前的数据

    private Integer limitSize = 1000; //单次处理记录条数

    private Integer day;//多少天

    public static JobParamVO getInstance(String param){

        if(StringUtils.isEmpty(param)) {
            return new JobParamVO();
        }

        JobParamVO jobParam = JSONObject.parseObject(param, JobParamVO.class);
        if(jobParam==null || jobParam.getBeforeMinutes()==null
                || jobParam.getLimitSize() ==null || jobParam.getMaxRetries()==null){
            return new JobParamVO();
        }

        if(jobParam.getBeforeMinutes() < 1){
            jobParam.setBeforeMinutes(1);
        }
        if(jobParam.getLimitSize() < 1){
            jobParam.setLimitSize(1);
        }
        if(jobParam.getMaxRetries()<1){
           jobParam.setMaxRetries(1);
        }

        return jobParam;
    }
}
